Column

Total Diapers Per Day

Total Both Diapers per Day

Total Wet Diapers per Day

Total Dirty Diapers per Day

Column

Diaper Type

Daily Statistics

---
title: "Fiona Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    social: menu
    source_code: embed
    vertical_layout: scroll
    theme: spacelab
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(rio)
library(here)
library(colorblindr)
library(gghighlight)
library(forcats)
library(ggrepel)
library(gt)
library(knitr)
library(kableExtra)
library(reactable)
library(plotly)

opts_chunk$set(echo = FALSE,
               fig.width = 5,
               fig.height = 6)

theme_set(theme_minimal(base_size = 8))

diaper <- import(here("data", "fiona_diaper2.sav"),
               setclass = "tbl_df") %>% 
  characterize() %>% 
  janitor::clean_names() 

head(diaper)

feed <- import(here("data", "fiona_feed2.sav"),
               setclass = "tbl_df") %>% 
  characterize() %>% 
  janitor::clean_names() 

head(feed)

fiona <- full_join(diaper, feed)

fiona_1 <- fiona %>% 
  rename("Wet" = total_wet,
         "Dirty" = total_dirty,
         "Both" = total_both)

head(fiona_1)

fiona_tidy <- fiona_1 %>% 
  pivot_longer(
    c(4:6),
    names_to = "diaper_type",
    values_to = "total"
  )

head(fiona)
head(fiona_tidy)
```


Column {.tabset data-width=750}
-----------------------------------------------------------------------

### Total Diapers Per Day

```{r diaper plot, fig.width=7}
line_plot <- ggplot(fiona, aes(date, total_diaper)) +
  geom_line(lwd = 1.6,
            color = "gray80") +
  scale_y_continuous(limits = c(0, 16),
                     breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16)) +
  geom_area(fill = "cornflowerblue",
            alpha = 0.3) +
  geom_point(size = 2, 
             color = "magenta") +
  geom_text_repel(aes(label = total_diaper),
                  size = 4) +
  theme(plot.title = element_text(color = "black", 
                                  size = 12, 
                                  face = "bold", 
                                  hjust = 0.5),
        axis.text = element_text(size = 10),
        axis.title=element_text(size=10)) +
  labs(x = "Date",
       y = "Total",
       title = "Number of Diapers per Day")

ggplotly(line_plot)
```

### Total Both Diapers per Day 
```{r both diaper plot data clean, include=FALSE}
head(fiona)

both_diapers <- fiona %>% 
  select(date, total_both)

```

```{r both diaper plot, fig.width=7}
both_plot <- ggplot(both_diapers, aes(date, total_both)) +
  geom_line(lwd = 1.6,
            color = "gray80") +
  scale_y_continuous(limits = c(0, 16),
                     breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16)) +
  geom_area(fill = "cornflowerblue",
            alpha = 0.3) +
  geom_point(size = 2, 
             color = "magenta") +
  geom_text_repel(aes(label = total_both),
                  size = 4) +
  theme(plot.title = element_text(color = "black", 
                                  size = 12, 
                                  face = "bold", 
                                  hjust = 0.5),
        axis.text = element_text(size = 10),
        axis.title=element_text(size=10)) +
  labs(x = "Date",
       y = "Total",
       title = "Number of Both Diapers per Day")

ggplotly(both_plot)
```


### Total Wet Diapers per Day 
```{r wet diaper plot data clean, include=FALSE}
head(fiona)

wet_diapers <- fiona %>% 
  select(date, total_wet)

```

```{r wet diaper plot, fig.width=7}
wet_plot <- ggplot(wet_diapers, aes(date, total_wet)) +
  geom_line(lwd = 1.6,
            color = "gray80") +
  scale_y_continuous(limits = c(0, 16),
                     breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16)) +
  geom_area(fill = "cornflowerblue",
            alpha = 0.3) +
  geom_point(size = 2, 
             color = "magenta") +
  geom_text_repel(aes(label = total_wet),
                  size = 4) +
  theme(plot.title = element_text(color = "black", 
                                  size = 12, 
                                  face = "bold", 
                                  hjust = 0.5),
        axis.text = element_text(size = 10),
        axis.title=element_text(size=10)) +
  labs(x = "Date",
       y = "Total",
       title = "Number of Wet Diapers per Day")

ggplotly(wet_plot)
```


### Total Dirty Diapers per Day 
```{r dirty diaper plot data clean, include=FALSE}
head(fiona)

dirty_diapers <- fiona %>% 
  select(date, total_dirty)

```

```{r dirty diaper plot, fig.width=7}
dirty_plot <- ggplot(dirty_diapers, aes(date, total_dirty)) +
  geom_line(lwd = 1.6,
            color = "gray80") +
  scale_y_continuous(limits = c(0, 16),
                     breaks = c(0, 2, 4, 6, 8, 10, 12, 14, 16)) +
  geom_area(fill = "cornflowerblue",
            alpha = 0.3) +
  geom_point(size = 2, 
             color = "magenta") +
  geom_text_repel(aes(label = total_dirty),
                  size = 4) +
  theme(plot.title = element_text(color = "black", 
                                  size = 12, 
                                  face = "bold", 
                                  hjust = 0.5),
        axis.text = element_text(size = 10),
        axis.title=element_text(size=10)) +
  labs(x = "Date",
       y = "Total",
       title = "Number of Dirty Diapers per Day")

ggplotly(dirty_plot)
```


Column {data-width=350}
-----------------------------------------------------------------------

### Diaper Type
```{r diaper type data cleaning, include=FALSE}
head(fiona_tidy)
head(fiona_1)

fiona_tidy %>% 
  count(total)

diaper_type <- fiona_tidy$diaper_type
diaper_total <- sum(fiona_tidy$total)

diapers <- tibble(diaper_type, diaper_total)


Wet <- sum(fiona_1$Wet)
Dirty <- sum(fiona_1$Dirty)
Both <- sum(fiona_1$Both)

diapers_2 <- tibble(Wet, Dirty, Both)

diaper_tidy <- diapers_2 %>% 
  pivot_longer(
    c(1:3),
    names_to = "diaper_type",
    values_to = "total"
  )

diaper_position <- c("Wet", "Dirty", "Both")
```

```{r diaper type}
dplot <- ggplot(diaper_tidy, aes(diaper_type, total)) +
  geom_col(fill = "blue", 
           alpha = 0.7) +
  scale_x_discrete(limits = diaper_position) +
  scale_y_continuous(limits = c(0, 1000),
                     breaks = c(0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)) +
  geom_text(aes(label = total),
             position = position_stack(vjust = 0.5),
            color = "white",
            size = 5) +
  theme(panel.grid.major.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_line(color = "gray80")) +
  theme(plot.title = element_text(color = "black", size = 12, face = "bold", hjust = 0.5),
        axis.text = element_text(size = 10),
        axis.title=element_text(size=10),
        strip.text = element_text(size = 10)) +
  labs(x = "Diaper Type",
       y = "Total",
       title = "Total Number of Diaper Type")

ggplotly(dplot)

```

### Daily Statistics

```{r table summary clean, include=FALSE}
head(fiona)

fiona_table <- fiona %>% 
  summarize(mean(total_diaper),
            sd(total_diaper),
            mean(total_wet),
            mean(total_dirty),
            mean(total_both),
            mean(feedings),
            sd(feedings))

reactable(fiona_table)

fiona_table <- fiona_table %>% 
  rename("Mean Total Diapers" = "mean(total_diaper)",
         "SD Total Diapers" = "sd(total_diaper)",
         "Mean Wet Diapers" = "mean(total_wet)",
         "Mean Dirty Diapers" = "mean(total_dirty)",
         "Mean Both Diapers" = "mean(total_both)",
         "Mean Feedings" = "mean(feedings)",
         "SD Feedings" = "sd(feedings)")

```

```{r table}

reactable(fiona_table, columns = list(
  "Mean Total Diapers" = colDef(format = colFormat(digits = 2)),
  "SD Total Diapers" = colDef(format = colFormat(digits = 2)),
  "Mean Wet Diapers" = colDef(format = colFormat(digits = 2)),
  "Mean Dirty Diapers" = colDef(format = colFormat(digits = 2)),
  "Mean Both Diapers" = colDef(format = colFormat(digits = 2)),
  "Mean Feedings" = colDef(format = colFormat(digits = 2)),
  "SD Feedings" = colDef(format = colFormat(digits = 2))),
  height = 500,
  striped = TRUE,
  compact = TRUE,
  outlined = TRUE)
```